package com.woniu.consumer;



import com.rabbitmq.client.Channel;
import com.woniu.util.ConstantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

@Component
@Slf4j
public class CheckProductConsumer {
    @Resource
    private RedisTemplate redisTemplateInit;
    @RabbitListener(queues = {ConstantUtil.RABBIT_QUEUE})
    public void consume(String msg, Channel channel, Message message){
        try {
            log.info("消费者收到消息：{}", msg);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}

